import { createRouter, createWebHashHistory } from 'vue-router'

import login from '@/views/login'
import layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: login,
    hidden: true,
    meta: { title: 'login', icon: 'dashboard' },
  },
  {
    path: '/',
    component: () => import('@/views/home'),
    hidden: true,
    meta: { title: '主页', icon: 'home' },
  },
  {
    path: '/Page404',
    name: 'Page404',
    hidden: true,
    meta: { title: '404', icon: '404' },
    component: () => import('@/views/exception/page404'),
  },
  {
    path: '/OtherError',
    name: 'OtherError',
    hidden: true,
    meta: { title: 'error', icon: 'error' },
    component: () => import('@/views/exception/otherError'),
  },
  {
    path: '/transitPage',
    name: 'transitPage',
    hidden: true,
    meta: { title: '转换页面', icon: 'home' },
    component: () => import('@/views/transitPage'),
  },
  {
    path: '/version',
    name: 'version',
    hidden: true,
    meta: { title: '更新日志', icon: 'home' },
    component: () => import('@/views/toolsView/version/index.vue'),
  },
]

const unitTestingRouters = [
  {
    path: '/testCrop',
    name: 'testCrop',
    hidden: true,
    meta: { title: 'testCrop', icon: 'home' },
    component: () => import('@/views/testView/testCrop/index.vue'),
  },
  {
    path: '/testImageDrag',
    name: 'testImageDrag',
    hidden: true,
    meta: { title: 'testImageDrag', icon: 'home' },
    component: () => import('@/views/testView/testImageDrag/index.vue'),
  },
]

export const asyncRoutes = [
  {
    path: '/risk',
    component: layout,
    redirect: 'waitingRiskScreening',
    name: 'risk',
    meta: {
      title: '风险筛查',
      icon: 'documentation',
      className: 'risk',
      homeIcon: 'home1',
      bgColor: 'color-1',
    },
    children: [
      {
        path: 'waitingRiskScreening',
        name: 'waitingRiskScreening',
        meta: { title: '风险筛查', className: 'risk' },
        component: () => import('@/views/waitingImp'),
      },
      {
        path: 'riskScreening',
        name: 'riskScreening',
        hidden: true,
        redirect: 'riskWithScreening',
        meta: {
          title: '风险筛查详情',
          className: 'risk',
          noCache: true,
          activeMenu: '/risk/waitingRiskScreening',
          hiddenWithBreadcrumb: true,
        },
        component: () => import('@/views/reception'),
        children: [
          {
            path: 'riskWithScreening',
            name: 'riskWithScreening',
            hidden: true,
            meta: {
              title: '筛查',
              noCache: true,
              className: 'risk',
              activeMenu: '/risk/waitingRiskScreening',
              cacheRouterGroup: '/risk/waitingRiskScreening',
            },
            component: () =>
              import('@/views/reception/components/screening.vue'),
          },
          {
            path: 'riskWithMedicalRecord',
            name: 'riskWithMedicalRecord',
            hidden: true,
            meta: {
              title: '风险筛查',
              noCache: true,
              className: 'risk',
              activeMenu: '/risk/waitingRiskScreening',
              cacheRouterGroup: '/risk/waitingRiskScreening',
            },
            component: () =>
              import('@/views/reception/components/medicalRecordView.vue'),
          },
          {
            path: 'riskWithAssessment',
            name: 'riskWithAssessment',
            hidden: true,
            meta: {
              title: '评估',
              noCache: true,
              className: 'risk',
              activeMenu: '/risk/waitingRiskScreening',
              cacheRouterGroup: '/risk/waitingRiskScreening',
            },
            component: () =>
              import('@/views/reception/components/screening.vue'),
          },
        ],
      },
    ],
  },
  {
    path: '/workbench',
    component: layout,
    redirect: 'waitingImp',
    name: 'workbench',
    meta: {
      title: '工作台',
      icon: 'documentation',
      className: 'workbench',
      homeIcon: 'home2',
      bgColor: 'color-2',
    },
    children: [
      {
        path: 'waitingImp',
        name: 'waitingImp',
        meta: { title: '待诊患者', className: 'workbench' },
        component: () => import('@/views/waitingImp'),
      },
      {
        path: 'patientList',
        name: 'patientList',
        meta: { title: '患者列表', className: 'workbench' },
        component: () => import('@/views/patientList'),
      },
      {
        path: 'patientInfo',
        name: 'patientInfo',
        hidden: true,
        meta: {
          title: '患者信息',
          noCache: true,
          className: 'workbench',
          activeMenu: '/workbench/patientList',
        },
        component: () => import('@/views/patientInfo'),
      },
      {
        path: 'reception',
        name: 'reception',
        hidden: true,
        redirect: 'medicalRecord',
        meta: {
          title: '病历信息',
          noCache: true,
          className: 'workbench',
          activeMenu: '/workbench/waitingImp',
          cacheRouterGroup: '/workbench/waitingImp',
          hiddenWithBreadcrumb: true,
        },
        component: () => import('@/views/reception'),
        children: [
          {
            path: 'screening',
            name: 'screening',
            hidden: true,
            meta: {
              title: '筛查',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            component: () =>
              import('@/views/reception/components/screening.vue'),
            // props: (route) => ({ pid: route.query.id }),
          },
          {
            path: 'medicalRecord',
            name: 'medicalRecord',
            hidden: true,
            meta: {
              title: '病历',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            // component: () => import('@/views/waitingImp'),
            component: () =>
              import('@/views/reception/components/medicalRecordView.vue'),
            // props: (route) => ({ pid: route.query.id }),
          },
          {
            path: 'assessment',
            name: 'assessment',
            hidden: true,
            meta: {
              title: '评估',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            // component: () => import('@/views/waitingImp'),
            component: () =>
              import('@/views/reception/components/screening.vue'),
            // props: (route) => ({ pid: route.query.id }),
          },
          {
            path: 'treatmentPlan',
            name: 'treatmentPlan',
            hidden: true,
            meta: {
              title: '治疗方案',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            // component: () => import('@/views/waitingImp'),
            component: () => import('@/views/reception/components/actionPlan'),
            // props: (route) => ({ pid: route.query.id }),
          },
          {
            path: 'emrTreatmentActionPlan',
            name: 'emrTreatmentActionPlan',
            hidden: true,
            meta: {
              title: '行动计划',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            // component: () => import('@/views/waitingImp'),
            component: () =>
              import('@/views/reception/components/emrTreatmentActionPlan'),
            // props: (route) => ({ pid: route.query.id }),
          },
          {
            path: 'prescription',
            name: 'prescription',
            hidden: true,
            meta: {
              title: '处方',
              noCache: true,
              className: 'workbench',
              activeMenu: '/workbench/waitingImp',
              cacheRouterGroup: '/workbench/waitingImp',
            },
            // component: () => import('@/views/waitingImp'),
            component: () =>
              import('@/views/reception/components/prescription'),
            // props: (route) => ({ pid: route.query.id }),
          },
        ],
      },
      {
        path: 'referral',
        name: 'referral',
        meta: { title: '转诊管理', className: 'workbench' },
        component: () => import('@/views/referral'),
      },
      {
        path: 'epidemiologicalInvestigationManage',
        name: 'epidemiologicalInvestigationManage',
        meta: { title: '初筛管理', className: 'workbench' },
        component: () =>
          import('@/views/workbench/epidemiologicalInvestigationManage'),
      },
      {
        path: 'epidemiologicalInvestigationInfo',
        name: 'epidemiologicalInvestigationInfo',
        hidden: true,
        meta: {
          title: '初筛详情',
          className: 'workbench',
          noCache: true,
          activeMenu: '/workbench/epidemiologicalInvestigationManage',
        },
        component: () =>
          import('@/views/workbench/epidemiologicalInvestigationInfo'),
      },
      {
        path: 'contentManagement',
        name: 'contentManagement',
        meta: { title: '内容管理', className: 'workbench' },
        component: () => import('@/views/workbench/contentManagement'),
      },
      {
        path: 'remoteMeeting',
        name: 'remoteMeeting',
        meta: { title: '远程问诊管理', className: 'workbench' },
        component: () => import('@/views/workbench/remoteMeeting'),
      },
    ],
  },
  {
    path: '/setting',
    component: layout,
    redirect: 'roles',
    name: 'setting',
    meta: {
      title: '系统设置',
      icon: 'documentation',
      className: 'setting',
      homeIcon: 'home3',
      bgColor: 'color-4',
    },
    children: [
      {
        path: 'roles',
        name: 'roles',
        meta: { title: '角色维护' },
        component: () => import('@/views/roles'),
      },
      {
        path: 'roleSetting',
        name: 'roleSetting',
        hidden: true,
        meta: {
          title: '角色设置',
          activeMenu: '/setting/roles',
          noCache: true,
          className: 'setting',
        },
        component: () => import('@/views/roleSetting'),
      },
      {
        path: 'orgInfo',
        name: 'orgInfo',
        hidden: true,
        meta: {
          title: '机构信息',
          activeMenu: '/setting/orgList',
          className: 'setting',
        },
        component: () => import('@/views/orgInfo'),
      },
      {
        path: 'orgList',
        name: 'orgList',
        meta: { title: '机构管理', className: 'setting' },
        component: () => import('@/views/orgList'),
      },
      {
        path: 'orgPersonnelList',
        name: 'orgPersonnelList',
        meta: { title: '机构人员管理', className: 'setting' },
        component: () => import('@/views/orgPersonnelList'),
      },
      {
        path: 'personnelInfo',
        name: 'personnelInfo',
        hidden: true,
        meta: {
          title: '机构人员信息',
          activeMenu: '/setting/orgPersonnelList',
          noCache: true,
          className: 'setting',
        },
        component: () => import('@/views/personnelInfo'),
      },
      {
        path: 'departments',
        name: 'departments',
        meta: { title: '科室维护', className: 'setting' },
        component: () => import('@/views/departments'),
      },
      {
        path: 'departmentInfo',
        name: 'departmentInfo',
        hidden: true,
        meta: {
          title: '科室信息',
          activeMenu: '/setting/departments',
          noCache: true,
          className: 'setting',
        },
        component: () => import('@/views/departmentInfo'),
      },
      {
        path: '/userLog',
        name: 'userLog',
        meta: { title: '操作日志', className: 'setting' },
        component: () => import('@/views/userLog'),
      },
    ],
  },
  {
    path: '/meeting',
    component: layout,
    redirect: 'meetingHall',
    name: 'meeting',
    meta: {
      title: '医教通',
      icon: 'documentation',
      className: 'meeting',
      homeIcon: 'home4',
      bgColor: 'color-7',
    },
    children: [
      {
        path: 'meetingHall',
        name: 'meetingHall',
        meta: { title: '会议大厅', className: 'meeting' },
        component: () => import('@/views/meetingHall'),
      },
    ],
  },
  {
    path: '/ordnanceData',
    component: layout,
    redirect: 'medicineManage',
    name: 'ordnanceData',
    meta: {
      title: '药械数据',
      icon: 'documentation',
      className: 'ordnanceData',
      bgColor: 'color-6',
      homeIcon: 'home5',
    },
    children: [
      {
        path: 'medicineManage',
        name: 'medicineManage',
        meta: { title: '药品管理', className: 'ordnanceData' },
        component: () => import('@/views/ordnanceData/medicineManage'),
      },
      {
        path: 'deviceManage',
        name: 'deviceManage',
        meta: { title: '器械管理', className: 'ordnanceData' },
        component: () => import('@/views/ordnanceData/deviceManage'),
      },
      {
        path: 'addMedicine',
        name: 'addMedicine',
        hidden: true,
        meta: {
          title: '新增药物',
          activeMenu: '/ordnanceData/medicineManage',
          className: 'ordnanceData',
          noCache: true,
        },
        component: () => import('@/views/ordnanceData/addMedicine'),
      },
      {
        path: 'addDevice',
        name: 'addDevice',
        hidden: true,
        meta: {
          title: '新增器械',
          activeMenu: '/ordnanceData/deviceManage',
          className: 'ordnanceData',
          noCache: true,
        },
        component: () => import('@/views/ordnanceData/addDevice'),
      },
    ],
  },
  {
    path: '/templateManage',
    component: layout,
    redirect: 'asthmaTemplateManage',
    name: 'templateManage',
    meta: {
      title: '模板管理',
      icon: 'documentation',
      className: 'templateManage',
      homeIcon: 'home6',
      bgColor: 'color-10',
    },
    children: [
      {
        path: 'asthmaTemplateManage',
        name: 'asthmaTemplateManage',
        meta: {
          title: '西医哮喘治疗方案模板管理',
          className: 'templateManage',
        },
        component: () => import('@/views/templateManage/asthmaTemplateManage'),
      },
      {
        path: 'rhinitisTemplateManage',
        name: 'rhinitisTemplateManage',
        meta: {
          title: '变应性鼻炎治疗方案模板管理',
          className: 'templateManage',
        },
        component: () =>
          import('@/views/templateManage/rhinitisTemplateManage'),
      },
      {
        path: 'cnAsthmaTemplateManage',
        name: 'cnAsthmaTemplateManage',
        meta: {
          title: '中医哮喘治疗方案模板管理',
          className: 'templateManage',
        },
        component: () =>
          import('@/views/templateManage/cnAsthmaTemplateManage'),
      },
      {
        path: 'addAsthmaTemplate',
        name: 'addAsthmaTemplate',
        hidden: true,
        meta: {
          title: '添加西医哮喘模板',
          noCache: true,
          className: 'templateManage',
          activeMenu: '/templateManage/asthmaTemplateManage',
        },
        component: () => import('@/views/templateManage/addAsthmaTemplate'),
      },
      {
        path: 'addRhinitisTemplate',
        name: 'addRhinitisTemplate',
        hidden: true,
        meta: {
          title: '添加变应性鼻炎模板',
          noCache: true,
          className: 'templateManage',
          activeMenu: '/templateManage/rhinitisTemplateManage',
        },
        component: () => import('@/views/templateManage/addRhinitisTemplate'),
      },
      {
        path: 'addCNAsthmaTemplate',
        name: 'addCNAsthmaTemplate',
        hidden: true,
        meta: {
          title: '添加中医哮喘治疗方案',
          noCache: true,
          className: 'templateManage',
          activeMenu: '/templateManage/cnAsthmaTemplateManage',
        },
        component: () => import('@/views/templateManage/addCNAsthmaTemplate'),
      },
      {
        path: 'prescriptionTemplateManage',
        name: 'prescriptionTemplateManage',
        meta: { title: '处方模板管理', className: 'templateManage' },
        component: () =>
          import('@/views/templateManage/prescriptionTemplateManage'),
      },
      {
        path: 'addPrescriptionTemplate',
        name: 'addPrescriptionTemplate',
        hidden: true,
        meta: {
          title: '添加处方模板',
          noCache: true,
          className: 'templateManage',
          activeMenu: '/templateManage/prescriptionTemplateManage',
        },
        component: () =>
          import('@/views/templateManage/addPrescriptionTemplate'),
      },
      {
        path: 'normalTempate',
        name: 'normalTempate',
        meta: {
          title: '病历模板',
          className: 'templateManage',
          activeMenu: '/templateManage/normalTempate',
        },
        component: () => import('@/views/templateManage/normalTempate'),
      },
      {
        path: 'addNormalTempate',
        name: 'addNormalTempate',
        hidden: true,
        meta: {
          title: '添加病历模板',
          noCache: true,
          className: 'templateManage',
          activeMenu: '/templateManage/normalTempate',
        },
        component: () => import('@/views/templateManage/addNormalTempate'),
      },
    ],
  },
  {
    path: '/chartAnalysis',
    component: layout,
    redirect: 'chartPage',
    name: 'chartAnalysis',
    meta: {
      title: '统计分析',
      icon: 'documentation',
      className: 'chartAnalysis',
      homeIcon: 'home7',
      bgColor: 'color-8',
    },
    children: [
      {
        path: 'chartPage',
        name: 'chartPage',
        meta: { title: '数据分析', className: 'chartAnalysis' },
        component: () => import('@/views/statistics/chartPage'),
      },
      {
        path: 'chartDetails',
        name: 'chartDetails',
        hidden: true,
        meta: {
          title: '数据分析详情',
          className: 'chartAnalysis',
          noCache: true,
          activeMenu: '/chartAnalysis/chartPage',
        },
        component: () => import('@/views/statistics/chartDetails'),
      },
    ],
  },
  {
    path: '/shop',
    name: 'shop',
    redirect: 'manageShops',
    component: layout,
    meta: {
      title: '商城购买',
      icon: 'documentation',
      className: 'shop',
      homeIcon: 'home8',
      bgColor: 'color-12',
    },
    children: [
      {
        path: 'manageShops',
        name: 'manageShops',
        meta: { title: '商品管理', className: 'shop' },
        component: () => import('@/views/shops/views/manageShops'),
      },
      {
        path: 'editShops',
        name: 'editShops',
        hidden: true,
        meta: {
          title: '商品编辑',
          className: 'shop',
          activeMenu: '/shop/manageShops',
          noCache: true,
        },
        component: () => import('@/views/shops/views/editShops'),
      },
      {
        path: 'orderDetails',
        name: 'orderDetails',
        hidden: true,
        meta: {
          title: '订单详情',
          className: 'shop',
          activeMenu: '/shop/orderManage',
          noCache: true,
        },
        component: () => import('@/views/shops/views/orderDetails'),
      },
      {
        path: 'orderManage',
        name: 'orderManage',
        meta: { title: '订单管理', className: 'shop' },
        component: () => import('@/views/shops/views/orderManage'),
      },
      {
        path: 'MKT',
        name: 'MKT',
        meta: { title: '营销分类', className: 'shop' },
        component: () => import('@/views/shops/views/MKTCategoryManage'),
      },
      {
        path: 'goodsTypes',
        name: 'goodsTypes',
        meta: { title: '商品分类', className: 'shop' },
        component: () => import('@/views/shops/views/MKTCategoryManage'),
      },
      {
        path: 'shopSetting',
        name: 'shopSetting',
        meta: { title: '基础设置', className: 'shop' },
        component: () => import('@/views/shops/views/shopSetting'),
      },
    ],
  },
]

export const async404 = [
  {
    path: '/:pathMatch(.*)*',
    name: 'NOTFOUND',
    component: () => import('@/views/exception/page404'),
    hidden: true,
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes:
    process.env.NODE_ENV !== 'development'
      ? constantRoutes
      : constantRoutes.concat(unitTestingRouters),
})

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
